package com.dw.etl.core.service;

import com.dw.etl.common.util.UUIDUtil;
import  com.dw.etl.common.vo.PaginationVO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import com.dw.etl.core.api.MdBaseDictService;
import com.dw.etl.core.mapper.MdBaseDictMapper;
import com.dw.etl.core.bean.model.MdBaseDict;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * mdBaseDict服务实现类
 * Created by hozeData on 2021/07/13.
 */
@Service
@Transactional
public class MdBaseDictServiceImpl implements MdBaseDictService{

    private static final Logger LOGGER = LoggerFactory.getLogger(MdBaseDictServiceImpl.class);

    @Autowired
    private MdBaseDictMapper mdBaseDictMapper;

    @Override
    public int insert(MdBaseDict mdBaseDict) {
        if(StringUtils.isEmpty(mdBaseDict.getIdDict())){
            String uuid32 = UUIDUtil.getUUID32();
            mdBaseDict.setIdDict(uuid32);
        }
        return mdBaseDictMapper.insert(mdBaseDict);
    }

    @Override
    public int insertSelective(MdBaseDict mdBaseDict)  {
        if(StringUtils.isEmpty(mdBaseDict.getIdDict())){
            String uuid32 = UUIDUtil.getUUID32();
            mdBaseDict.setIdDict(uuid32);
        }
        return mdBaseDictMapper.insertSelective(mdBaseDict);
    }

    @Override
    public int deleteById(String idDict)  {
        return mdBaseDictMapper.deleteByPrimaryKey(idDict);
    }

    @Override
    public int updateByIdSelective(MdBaseDict mdBaseDict)  {

        return mdBaseDictMapper.updateByPrimaryKeySelective(mdBaseDict);
    }

    @Override
    public int updateById(MdBaseDict mdBaseDict)  {
        return mdBaseDictMapper.updateByPrimaryKey(mdBaseDict);
    }

    @Override
    public MdBaseDict getById(String idDict)  {
        return mdBaseDictMapper.selectByPrimaryKey(idDict);
    }

    @Override
    public List<MdBaseDict> findByModel(MdBaseDict mdBaseDict)  {
        return mdBaseDictMapper.findByModel(mdBaseDict);
    }

    @Override
    public PaginationVO<MdBaseDict> findPageByModel(MdBaseDict mdBaseDict, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum == null? 1 : pageNum, pageSize == null? 10 : pageSize);
        List<MdBaseDict> quesList = mdBaseDictMapper.findByModel(mdBaseDict);
        PageInfo<MdBaseDict> pageInfo = new PageInfo<>(quesList);
        PaginationVO<MdBaseDict> paginationVo = new PaginationVO(pageInfo.getTotal(), pageInfo.getList());
        return paginationVo;
    }





}
